package com.itheima.InnerClass5;

import java.util.Arrays;
import java.util.Comparator;

public class test {
    public static void main(String[] args) {
        Student []students=new Student[6];
        students[0]= new Student("张三", 18, 1.75, "男");
        students[1]= new Student("张三", 18, 1.75, "男");
        students[2]= new Student("张三", 30, 1.75, "男");
        students[3]= new Student("张三", 18, 1.75, "男");
        students[4]= new Student("张三", 18, 1.75, "男");
        students[5]= new Student("张三", 18, 1.78, "男");
        //sort方法会调用匿名内部类对象的compare方法 对数组中的学生对象进行两两比较
        //根据升高排
//        Arrays.sort( students, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                //指定排序规则：
//                //如果你认为左边对象大于右边对象，那么返回正数
//                //如果你认为左边对象小于右边对象，那么返回负数
//                //如果相等，那么返回0
////                if(o1.getAge()>o2.getAge())
////                {
////                    return 1;
////                }
////                else if(o1.getAge()<o2.getAge())
////                {
////                    return -1;
////                }
////                else {
////                    return 0;
////                }
//                return o1.getAge()-o2.getAge();
//            }
//        });
        //根据年龄排
        Student s1=new Student();
        //Arrays.sort(students,(o1, o2) ->s1.compare(o1, o2) );
        //最终化简
        Arrays.sort( students,s1::compare);
        //遍历学生数组
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            System.out.println(student.getName()+"---"+student.getAge()+"---"+student.getHeight()+"---"+student.getSex());
        }
    }
}
